import {createStore, combineReducers, compose, applyMiddleware} from "redux"
import UserRedux from './reduces/UserRedux'
import reduxPromise from 'redux-promise'
import reduxTrunk from 'redux-thunk'
import {persistStore, persistReducer} from 'redux-persist'
import sessionStorage from 'redux-persist/lib/storage/session';
import MyFloatButtonRedux from './reduces/MyFloatButtonRedux'
import MyLoadingRedux from "./reduces/MyLoadingRedux";
//持久化定义配置的信息
const persistConfig = {
    key: "root",
    storage: sessionStorage,
    whitelist: ['UserRedux']
}

//reducers 合并
const rootReducer = combineReducers({
    UserRedux,
    MyFloatButtonRedux,
    MyLoadingRedux
})

// 次持久化配置过的redux
const persistedReducer = persistReducer(persistConfig, rootReducer)

//开发工具配置
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

// 普通store
const store = createStore(persistedReducer, composeEnhancers(applyMiddleware(reduxTrunk, reduxPromise)))

// 持久store
const persistor = persistStore(store)

export {
    store,
    persistor
}
